﻿using System.Windows.Controls;
using System.Windows.Data;

namespace HobSoft.SoccerBet2014.Client.Common
{
    using ViewModels;

    public class BfAccountValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            var vmaccount = (value as BindingGroup).Items[0] as BfAccount;
            if (vmaccount == null)
                return ValidationResult.ValidResult;

            if (string.IsNullOrEmpty(vmaccount.Account))
                return new ValidationResult(false, "需要账号名称。");
            if (vmaccount.Account.Trim().Length < 2)
                return new ValidationResult(false, "需要账号名称（长度必须超过1字符）。");
            if (string.IsNullOrEmpty(vmaccount.Password))
                return new ValidationResult(false, "需要账号密码。");
            if (vmaccount.Password.Trim().Length < 2)
                return new ValidationResult(false, "需要账号密码（长度必须超过1字符）。");
            if (string.IsNullOrEmpty(vmaccount.AppKey))
                return new ValidationResult(false, "需要AppKey。");
            if (vmaccount.AppKey.Trim().Length < 2)
                return new ValidationResult(false, "需要AppKey（长度必须超过1字符）。");
            if (string.IsNullOrEmpty(vmaccount.CertificateFile))
                return new ValidationResult(false, "需要证书文件。");
            return ValidationResult.ValidResult;
        }
    }
}
